export default {
  // 计算总价格
  PriceTotal (state) {
    let total = 0
    // console.log(state);
    let checkitem = state.items.filter(el => el.isChecked)
      console.log(checkitem, "满足计算商品价格的商品")
      checkitem.forEach(el => {
        total += el.num * el.minPrice
    })
    state.total = parseFloat(total.toFixed(2))
    console.log(state.total, "价格");
  },
  // 改变全选
  setAllCheck (state, AllCheck) {
    state.isAllChecked = AllCheck
  },
  // 变成全选
  setCheck (state, isAllChecked) {
    state.items.forEach(el => { el.isChecked = isAllChecked})
  },
  // 删除商品
  setdelay (state, index) {
    state.items.splice(index, 1)
  },
  setAddCar (state, item) {
    if (state.items.find(el => el.id ===item.id)) {
      alert("请勿重复添加")
      return
    }
    // console.log(item,22222);
    item.isChecked = true
    state.items.unshift(item)
    alert("商品添加成功")
  }
}
